package cn.com.KnowNews.servlet;

import cn.com.KnowNews.service.imlp.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "FindByCateServlet",urlPatterns = "/FindByCate")
public class FindByCateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cate = request.getParameter("category");
        HttpSession session = request.getSession();
        System.out.println(cate);
        NewsServiceImpl newsService = new NewsServiceImpl();
        try {
           session.setAttribute("found",newsService.selectByCate(cate));
           System.out.println(newsService.selectByCate(cate));
           response.sendRedirect("/admin/showFoundNews.jsp");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
